
import 'package:get/get.dart';
import 'package:share_fit/app/tools/locale_tool.dart';

extension TranslationExtension on String {
  String get ts {
    if (Get.locale?.languageCode == null) return this;

    if (Get.fallbackLocale != null) {
      var fallback = Get.locale;
      fallback ??= Get.fallbackLocale!;
      final key = LocaleTool.locale;

      for (String transKeys in Get.translations.keys) {
        if (transKeys.contains(key) && Get.translations[transKeys]!.containsKey(this)) {
          return Get.translations[transKeys]![this]!;
        }
      }

      if (Get.translations.containsKey(fallback.languageCode) &&
          Get.translations[fallback.languageCode]!.containsKey(this)) {
        return Get.translations[fallback.languageCode]![this]!;
      }
      return this;
    } else {
      return this;
    }
  }
}